package com.example.leetcode.niuke;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class NiuKe13 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer count = scanner.nextInt();
        int i = -1;
        Map<Integer,Integer> map = new HashMap<>();
        int r = Integer.MIN_VALUE;
        while (i < count -1) {
            i++;
            int i1 = scanner.nextInt();
            if (map.containsKey(i1)) {
                r = Math.max(r,i - map.get(i1));
            }
            map.put(i1,i);
        }
        System.out.println(r);
    }
}
